class Solution(object):
    def distributeCandies(self, candies, num_people):
        """
        :type candies: int
        :type num_people: int
        :rtype: List[int]
        """
        t_max = int((2 * candies) ** 0.5)
        t_total = t_max * (t_max + 1) // 2
        if t_total <= candies:
            t_diff = candies - t_total
        else:
            t_max -= 1
            t_total = t_max * (t_max + 1) // 2
            t_diff = candies - t_total
        k = t_max // num_people
        out = [0] * num_people
        for i in range(num_people):
            out[i] = (2 * (i + 1) + (k - 1) * num_people) * k // 2
        index = 0
        for num in range(num_people * (t_max // num_people) + 1, t_max + 1):
            out[index] += num
            index += 1
        out[index] += t_diff
        return out




data = Solution()
candies = 50
num_people = 3
print(data.distributeCandies(candies, num_people))
